/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:${USER}
 * Date:${YEAR}-${MONTH}-${DAY}
 * ${TIME}
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }

    static int[] x1 = {1, -1, 0, 0};
    static int[] y1 = {0, 0, 1, -1};
    public int[][] flipChess (int[][] A, int[][] f) {
        // write code here
        for (int i = 0; i < f.length; i++) {
            for (int k = 0; k < 4; k++) {
                int newx = f[i][0] + x1[k] - 1;
                int newy = f[i][1] +y1[k]- 1;
                if (newx >= 0 && newy >= 0 && newx < A.length && newy < A.length) {
                    if (A[newx][newy] == 1)A[newx][newy] = 0;
                    else A[newx][newy] = 1;
                }
            }
        }
        return A;
    }

}